<?php
namespace app\common\model;

class JobRadioRecord extends Base
{
    /**
     * 新增比例记录
     * @param int $jobId  职位ID
     * @param float $radio  比例
     */
    public static function addRadio($jobId, $radio)
    {
        $addData = [
            'job_id' => $jobId,
            'radio'  => $radio,
        ];

        $flag = self::add($addData);
        if(!$flag) return false;
        return true;
    }

    /**
     * 查询某天比例
     * @param int $jobId  职位ID
     * @param date $time  时间戳
     */
    public static function getJobRadio($jobId, $time)
    {
        $radio = self::where([['job_id', '=', $jobId], ['create_time', '<=', $time]])->value('radio');
        return $radio ? $radio : 1;
    }
}